var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("GameEm"),
    s = t("BoxGift"),
    c = t("CatMoveCom"),
    p = cc._decorator,
    l = p.ccclass,
    d =
        (p.property,
        p.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.parentSort = null;
                e.boxParentNode = null;
                e.catParentNode = null;
                return e;
            }
            e.prototype.checkSort = function () {
                var t = this;
                EVUIEffView.emit(EVUIEffView.callSort, function (e) {
                    t.parentSort = e;
                });
            };
            e.prototype.onLoad = function () {
                EvCat.on(EvCat.makeCat1, this.makeGiftBox.bind(this), this);
                EvCat.on(EvCat.makeCat2, this.makeInvCat.bind(this), this);
            };
            e.prototype.addCatInvateTask = function (t, e, o, a, i, n, r) {
                var s = this,
                    p = QLooperNode.getNode(QLooperNode.tag_catAnimal);
                if (p) {
                    p.parent = this.parentSort;
                    p.setPosition(p.parent.convertToNodeSpaceAR(n));
                    ParseTool.setSortIndex(p);
                    var l = p.getComponent(c.default);
                    l.setFoodData(i);
                    var d = CacheDataManager.getEmployee();
                    l.setSkinData(this.getSkinData(t, d[3e3], e));
                    var u = this.getEquipInvateData(i.invData),
                        h = this.getInvateHatPos(i.invData);
                    l.setEquip(u, h);
                    l.setBaseData(t, e, o, a, r);
                } else
                    this.scheduleOnce(function () {
                        s.addCatTask(t, e, o, a, i, n, r);
                    }, 0.1);
            };
            e.prototype.getInvateHatPos = function (t) {
                for (
                    var e = t.id, o = CacheDataManager.getCostumeup(), a = CacheDataManager.getCostume(), i = {}, n = 0;
                    n < e.length;
                    n++
                ) {
                    var r = a[o[e[n].data].costume_id];
                    i[n + 1] = cc.v2(r.postion_x || 0, r.postion_y || 0);
                }
                return i;
            };
            e.prototype.getEquipInvateData = function (t) {
                var e = t.id,
                    o = {};
                if (3 == e.length) {
                    var a = CacheDataManager.getIcon();
                    o.front = {
                        hat: a[CacheDataManager.getEquipFrontIcon(e[0].data)].icon_name,
                        wear: a[CacheDataManager.getEquipFrontIcon(e[1].data)].icon_name,
                        arms: a[CacheDataManager.getEquipFrontIcon(e[2].data)].icon_name
                    };
                    o.back = {
                        hat: a[CacheDataManager.getEquipBackIcon(e[0].data)].icon_name,
                        wear: a[CacheDataManager.getEquipBackIcon(e[1].data)].icon_name,
                        arms: a[CacheDataManager.getEquipBackIcon(e[2].data)].icon_name
                    };
                }
                return o;
            };
            e.prototype.onDestroy = function () {
                EvCat.offTarget(this);
            };
            e.prototype.makeInvCat = function (t, e, o, a, i, n, r) {
                this.addCatInvateTask(e, o, a, n.typeIndex + "", i, this.boxParentNode.convertToWorldSpaceAR(n.pos), r);
            };
            e.prototype.makeGiftBox = function (t, e, o, a, i, n, s, c) {
                var p = this;
                this.checkSort();
                if (this.parentSort) {
                    this.boxParentNode ||
                        EVUIEffView.emit(EVUIEffView.callNode, r.CookingCallKey.npcBuildPos, 0, function (t) {
                            p.boxParentNode = t;
                        });
                    this.catParentNode ||
                        EVUIEffView.emit(EVUIEffView.callNode, r.CookingCallKey.npcWay1, 0, function (t) {
                            p.catParentNode = t;
                        });
                    if (this.boxParentNode && this.catParentNode) {
                        if (c) {
                            this.addCatTask(
                                e,
                                o,
                                a,
                                n.typeIndex + "",
                                i,
                                this.boxParentNode.convertToWorldSpaceAR(n.pos),
                                s
                            );
                            EvCat.emit(EvCat.reduceNpcBox, n, n.typeIndex);
                        } else
                            this.playGiftBox(this.parentSort, n.pos, function (t) {
                                p.addCatTask(e, o, a, n.typeIndex + "", i, t, s);
                                EvCat.emit(EvCat.reduceNpcBox, n, n.typeIndex);
                            });
                    } else
                        this.scheduleOnce(function () {
                            p.makeGiftBox(t, e, o, a, i, n, s, c);
                        }, 0.1);
                } else
                    this.scheduleOnce(function () {
                        p.makeGiftBox(t, e, o, a, i, n, s, c);
                    }, 0.1);
            };
            e.prototype.playGiftBox = function (t, e, o) {
                var a = this,
                    i = this.setLooperNode(QLooperNode.tag_boxGift, t, e);
                if (i) {
                    var n = i.getComponent(s.default);
                    ParseTool.setSortIndex(i);
                    n.play(o);
                } else
                    this.scheduleOnce(function () {
                        a.playGiftBox(t, e, o);
                    }, 0.5);
            };
            e.prototype.setLooperNode = function (t, e, o) {
                var a = this,
                    i = QLooperNode.getNode(t);
                if (i) {
                    i.parent = e;
                    i.setPosition(o);
                    return i;
                }
                this.scheduleOnce(function () {
                    a.setLooperNode(t, e, o);
                }, 0.2);
            };
            e.prototype.addCatTask = function (t, e, o, a, i, n, r) {
                var s = this,
                    p = QLooperNode.getNode(QLooperNode.tag_catAnimal);
                if (p) {
                    p.parent = this.parentSort;
                    p.setPosition(p.parent.convertToNodeSpaceAR(n));
                    ParseTool.setSortIndex(p);
                    var l = p.getComponent(c.default);
                    l.setFoodData(i);
                    l.setSkinData(this.getSkinData(t, i.data, e));
                    var d = this.getEquitSkin(i.data);
                    d = this.checkSkin(i.data, d);
                    l.setEquip(d, {1: cc.v2(0, 0)});
                    l.setBaseData(t, e, o, a, r);
                } else
                    this.scheduleOnce(function () {
                        s.addCatTask(t, e, o, a, i, n, r);
                    }, 0.1);
            };
            e.prototype.checkSkin = function (t, e) {
                if (t.hat) {
                    e.front.hat = t.hat;
                    e.back.hat = t.hat;
                }
                if (t.wear_Back) {
                    e.front.wear = t.wear_Front;
                    e.back.wear = t.wear_Back;
                }
                return e;
            };
            e.prototype.getSkinData = function (t, e) {
                var o = {};
                o.front = ParseTool.getFront(e);
                o.back = ParseTool.getBack(e);
                return o;
            };
            e.prototype.getEquitSkin = function (t) {
                var e = {};
                e.front = ParseTool.getEquitFront(t);
                e.back = ParseTool.getEquitBack(t);
                return e;
            };
            return n([l], e);
        })(cc.Component));
o.default = d;
